﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace PhotoKiosk.Model.Device
{
    public class Dok : IDevice
    {
        private DriveInfo _Drive = null;
        private List<Photo> _AllPhotos;

        public void LoadAllPhotos(List<string> i_FileExtensions)
        {
            if (_AllPhotos == null)
            {
                _AllPhotos = new List<Photo>();
                foreach (string file in Directory.GetFiles(_Drive.RootDirectory.FullName, "*.*", SearchOption.AllDirectories))
                {
                    if (i_FileExtensions.Contains(Path.GetExtension(file).ToUpperInvariant()))
                    {
                        _AllPhotos.Add(new Photo(file));
                    }
                }
            }
        }

        public List<Photo> AllPhotos()
        {
            return _AllPhotos;
        }


        public static bool IsConnected()
        {
            foreach (DriveInfo drive in DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.Removable))
            {
                if (drive.IsReady)
                {
                    return true;
                }
            }
            return false;
        }


        public bool Connect()
        {
            foreach (DriveInfo drive in DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.Removable))
            {
                if (drive.IsReady)
                {
                    _Drive = drive;
                    return true;
                }
            }
            return false;
        }

        public bool CopyFile(string i_Link, string i_to)
        {
            throw new NotImplementedException();
        }
    }
}
